
use "Surveys 1-12 Pollfish.dta", clear

*********************************
*Data Preparation 

*1. DEPENDENT VARIABLES

*2. INDEPENDENT VARIABLES
**2a. Socioeconomic variables
**2b. Party-related variables
**2c. Security-related variables

***********************
*****EXPERIMENT 5******
***********************
*1. Dependent Variable (Experiment 5) 
*DV
gen E5_crime_measures = Q26_eval 
label variable E5_crime_measures "DV: Support for a crime-reducing proposal by nature of proposal"
label define E5_crime_measures 1"Strongly disagree" 2"Disagree" 3"Neither agreee, nor disagree" 4"Agree" 5"Strongly agree", modify
label values E5_crime_measures E5_crime_measures
tab E5_crime_measures

*T1 - Territorial scope of policies
gen E5_vign1 = Q26_vign1
label define  E5_vign1 0 "undefined" 1 "violent municipalities", modify
label values E5_vign1 E5_vign1
tab E5_vign1
label variable E5_vign1 "Territorial scope of measures" 

*T2 - Nature of policies
gen E5_vign2 = Q26_vign2
label define  E5_vign2 0 "undefined" 1"youth education" 2"youth employment" 3"longer sentences" 4 "better prisons" 5"tougher policing", modify
label values  E5_vign2  E5_vign2
tab E5_vign2
label variable E5_vign2 "Nature of measures (welfare / punitive)" 

recode E5_vign2 3=4 4=3
label define  E5_vign2 0 "undefined" 1"youth education" 2"youth employment" 3 "in-prison rehabilitation" 4 "harsher sentences" 5"aggressive policing", modify
label values  E5_vign2  E5_vign2


*E5 (3 categories)
recode E5_crime_measures 1/2 = 1 3=2 4/5=3, gen(E5_crime_measures2)
label define  E5_crime_measures2 1 "Disagree" 2"Neither" 3"Agree", modify
label values E5_crime_measures2 E5_crime_measures2


***********************
*****EXPERIMENT 6******
***********************
*1. Dependent Variable (Experiment 6) 
*DV
gen E6_police_effectiveness= Q15_eval 
label variable E6_police_effectiveness "DV: Faith in the police catching the criminals"
label define E6_police_effectiveness 1"Not at all" 2"A little" 3"Somewhat" 4"A lot", modify
label values E6_police_effectiveness E6_police_effectiveness
tab E6_police_effectiveness

gen E6_police_misconduct = Q16_eval 
label variable E6_police_misconduct  "DV: Faith in the police catching the criminals"
label define E6_police_misconduct 1"Not at all" 2"A little" 3"Somewhat" 4"A lot", modify
label values E6_police_misconduct E6_police_misconduct
tab E6_police_misconduct

*T1 - Gender
gen E6_vign1 = Q15_vign1
label define  E6_vign1 0 "empty" 1 "female", modify
label values E6_vign1 E6_vign1
tab E6_vign1
label variable E6_vign1 "Gender" 

*T2 - Work background
gen E6_vign2 = Q15_vign2
label define  E6_vign2 0 "empty" 1"military" 2"private security" 3"vigilante" 4 "activist" 5"migrant", modify
label values  E6_vign2  E6_vign2
tab E6_vign2
label variable E6_vign2 "Nature of measures (welfare / punitive)" 


********************************
*Exp 6 - EFFECT CODING VARIABLES 

igenerate E6_vign1, gen(e6_vign1_effect) coding(effect)
rename e6_vign1_effect2 e6_vign1_female_effect
label variable e6_vign1_female_effect "female" 

igenerate E6_vign2, gen(e6_vign2_effect) coding(effect)
rename e6_vign2_effect2 e6_vign2_military_effect
rename e6_vign2_effect3 e6_vign2_private_effect
rename e6_vign2_effect4 e6_vign2_vigilante_effect
rename e6_vign2_effect5 e6_vign2_activist_effect
rename e6_vign2_effect6 e6_vign2_migrant_effect

label variable e6_vign2_military_effect "military" 
label variable e6_vign2_private_effect "private" 
label variable e6_vign2_vigilante_effect "vigilante" 
label variable e6_vign2_activist_effect "activist" 
label variable e6_vign2_migrant_effect "migrant"


***************************
*INDEPENDENT VARIABLES
*2a. Socioeconomic Variables
****************************

*State 
gen state = Q48
label variable state "State in Mexico" 

*Age
tab age_range
label define age_range 1 "18-24 yrs" 2"25-34 yrs" 3"35-44 yrs" 4"45-54 yrs" 5"+55 yrs", modify
label values age_range age_range
tab age_range, gen(age_groups)
label variable age_groups1 "18-24 yrs"
label variable age_groups2 "25-34 yrs"
label variable age_groups3 "35-44 yrs"
label variable age_groups4 "45-54 yrs"
label variable age_groups5 "+55 yrs"

*Age recoded
recode age_range 4/5=4, gen(age_range2) 
label define age_range2 1 "18-24 yrs" 2"25-34 yrs" 3"35-44 yrs" 4"+45 yrs", modify
label values age_range2 age_range2

*Gender
sum gender
recode gender 2=0, gen(female)
label variable female "Female"
label define female 1 "female" 0 "male", modify
label values female female 

*Education 
recode education 1/2=1 3/4=2 5=3 6=4, gen(education_cat)
tab education_cat
label variable education_cat "education level"
label define education 1"elementary/middle school" 2"high school / technical college" 3"university" 4"postgraduate", modify
label values education education_cat
tab education_cat, gen(edlevel)
label variable edlevel1 "elementary/middle school"
label variable edlevel2 "high school / technical college"
label variable edlevel3 "university"
label variable edlevel4 "postgraduate"

recode education_cat 1/2 =0 3/4=1, gen(college_higher) 
label variable college_higher "college education or higher"


*Income 
*Poor under 10,000 pesos
*Middle class 10,000 - 40,000 pesos 
*Rich over 40,000 pesos
recode Q50 1/2=1 3/6=2 7/8=3, gen(income_level)
tab income_level
label variable income_level "Income level (ordinal)" 
label define income 1"poor" 2"middle-class" 3"rich", modify
label values income_level income
tab income_level, gen(income_cat)
label define income_level 1"poor" 2"middle" 3"rich", modify
label values income_level income_level
label variable income_cat1 "Poor"
label variable income_cat2 "Middle-class"
label variable income_cat3 "Rich"

*Working status
tab Q17
recode Q17 2=0, gen(employed)
label variable employed "Employed / Working"
label define employed 0"Unemployed" 1"Employed", modify 
label values employed employed

recode Q19 0/1=0 2=1, gen(informal)
label variable informal "Informal worker"
label define informal 0"Noninformal" 1"Informal", modify
label values informal informal

*Public healthcare usage
recode Q37_10 1=1 2=0, gen(publichealth_usage)
label variable publichealth_usage "Have you used public healthcare services in the past year?"
label values publichealth_usage yesno

recode Q20 1=0 2=1 3=0, gen(publicinsurance)
label variable publicinsurance "Are medical expenses covered in your households with public healthcare insurance?"
label values publichealth_usage yesno


***************************
*Ideology related variables
*religiousity 
recode Q21 5=0 4= 1 3=2 2=3 1=4, gen(religiosity)
label variable religiosity "How often do you practice your religion?" 
label define religiosity 4 "At least once a day" 3 "At least once a week" 2"Several times a month" 1"Almost never" 0"Never", modify 
label values religiosity religiosity

*ideology 
recode Q38 0/33.33 = 0 33.34/66.65 = 1 66.66/100=2, gen (ideology)
label variable ideology "Self-ideological placement" 
label define ideology 0"Left" 1"Center" 2"Right", modify
label values ideology ideology
tab ideology, gen(self_placement)
label variable self_placement1 "Left" 
label variable self_placement2 "Center" 
label variable self_placement3 "Right" 

*ethnicity 
recode  Q24_2 2=0, gen(indigenous) 
label variable indigenous "Do you consider yourself indigenous?" 
label define indigenous 1 "indigenous" 0 "indigenous", modify
label values indigenous indigenous  

********************************
*2c. Party / political participation related variables
********************************
recode Q40 1=1 2/4=0 5=1 6=1 7=0 102= 0 103=0, gen(incumbent)
label variable incumbent "Supports incumbent parties" 
recode Q40 1=0 2/4=1 5=0 6=0 7=1 102= 1 103=0, gen(opposition)
label variable opposition "Supports opposition parties" 
recode Q40 1=0 2/4=0 5=0 6=0 7=0 102= 0 103=1, gen(noparty)
label variable noparty "Does not identify with any party" 
recode Q40 1=1 2/4=2 5=1 6=1 7=2 102= 2 103=3, gen(party_id)
label define party_id 1"incumbent" 2"opposition" 3"no party" 
label values party_id party_id 

*Voted 
recode Q37_1 2=0, gen(voted)
label variable voted "Voted in the last federal election" 

*Referendum 
recode Q37_2 2=0, gen(referendum)
label variable referendum "Participated in the presidential referendum" 

********************************
*2c. Security related variables
********************************
*Safety perceptions
recode Q23_1 1/2=1 3/5=0, gen(unsafe_neigh)
label variable unsafe_neigh "Feeling unsafe in the neighbourhood" 
recode Q23_2 1/2=1 3/5=0, gen(unsafe_state)
label variable unsafe_state "Feeling unsafe in the state" 
recode Q23_3 1/2=1 3/5=0, gen(unsafe_country)
label variable unsafe_country "Feeling unsafe in the country" 

recode Q23_1 1=4 2=3 3=2 4=1 5=0, gen(unsafe_neigh_ord)
label variable unsafe_neigh_ord "Feeling unsafe in the neighbourhood (ordinal)" 
recode Q23_2 1=4 2=3 3=2 4=1 5=0, gen(unsafe_state_ord)
label variable unsafe_state_ord "Feeling unsafe in the state (ordinal)" 
recode Q23_3 1=4 2=3 3=2 4=1 5=0, gen(unsafe_country_ord)
label variable unsafe_country_ord "Feeling unsafe in the country (ordinal)" 

*Security evaluations (present)
recode Q13_4 1/2=1 3/5=0, gen(seceval_neigh)
label variable seceval_neigh "Bad security situation in neighbourhood" 
recode Q13_3 1/2=1 3/5=0, gen(seceval_country)
label variable seceval_country "Bad security situation in country" 

recode Q13_4 1=4 2=3 3=2 4=1 5=0, gen(seceval_neigh_ord)
label variable seceval_neigh_ord "Bad security situation in neighbourhood (ordinal)" 
recode Q13_3 1=4 2=3 3=2 4=1 5=0, gen(seceval_country_ord)
label variable seceval_country_ord "Bad security situation in country (ordinal)" 


*Security evaluations (retospective)
recode Q14_4 1/2=1 3/5=0, gen(pastseceval_neigh)
label variable pastseceval_neigh "Worse security situation in neighbourhood" 
recode Q14_3 1/2=1 3/5=0, gen(pastseceval_country)
label variable pastseceval_country "Worse security situation in country" 

recode Q14_4 1=4 2=3 3=2 4=1 5=0, gen(pastseceval_neigh_ord)
label variable pastseceval_neigh_ord "Worse security situation in neighbourhood (ordinal)" 
recode Q14_3 1=4 2=3 3=2 4=1 5=0, gen(pastseceval_country_ord)
label variable pastseceval_country_ord "Worse security situation in country (ordinal)" 

*Own justice in neighbourhood 
recode Q28_5 1/2=0 3/5=1, gen(ownjustice_neigh)
label variable ownjustice_neigh "Likely that neighbours take justice in their own hands" 

*Vigilantes in neighbourhood 
recode Q43_1 2=0, gen(vigilantes_neigh)
label variable vigilantes_neigh "Neighbours organised into self-protection groups" 
label define vigilantes_neigh 1 "Watchgroups in neighborhood" 0"No watchgroups in neighbourhood", modify
label values vigilantes_neigh vigilantes_neigh

*Trust in the police
recode Q30_1 1/3=0 4/5=1, gen(trafficpolice)
label variable trafficpolice "Easy to bribe a traffic officer" 
recode Q30_2 1/3=0 4/5=1, gen(localpolice)
label variable localpolice "Easy to bribe a local police officer" 
recode Q30_3 1/3=0 4/5=1, gen(federalpolice)
label variable federalpolice "Easy to bribe a federal police officer"
recode Q30_1 1/3=0 4/5=1, gen(military)
label variable military "Easy to bribe a soldier"


recode Q30_1 1=0 2=1 3=2 4=3 5=4, gen(trafficpolice_ord)
label variable trafficpolice_ord "Easy to bribe a traffic officer (ordinal)" 
recode Q30_2 1=0 2=1 3=2 4=3 5=4, gen(localpolice_ord)
label variable localpolice_ord "Easy to bribe a local police officer (ordinal)" 
recode Q30_3 1=0 2=1 3=2 4=3 5=4, gen(federalpolice_ord)
label variable federalpolice_ord "Easy to bribe a federal police officer(ordinal)"
recode Q30_1 1=0 2=1 3=2 4=3 5=4, gen(military_ord)
label variable military_ord "Easy to bribe a solider (ordinal)" 


*Index of distrust in the police (additive) 
alpha trafficpolice_ord localpolice_ord federalpolice_ord military_ord, gen(bribe_officers_index)
label variable bribe_officers_index "How easy is to bribe security officers (index)" 


**********************************************************
*Crime victim 
recode Q41 2=0, gen(crime_victim) 
label variable crime_victim "Victim of a crime" 

*Violent crime victim 
recode Q42 0=0 1/2=1 3=2, gen(violence_victim) 
label define violence_victim 0"nonvictim" 1"violent crime victim" 2"nonviolent crime victim", modify
label variable violence_victim "Victim of violence" 

tab violence_victim, gen(victim)
label variable victim1 "nonvictim"
label variable victim2 "violent crime victim"
label variable victim3 "nonviolent crime victim" 

*Extorsion victim
recode Q43_4 2=0, gen(extorsion_victim)
label variable extorsion_victim "Changed telephone number due to extorsion" 

**************************************************************
*Fear of crime (changed behaviour) 
recode  Q43_2 2=0, gen(crime_fear) 
label variable crime_fear "Changed behaviour because of fear of crime" 
label define crime_fear 1 "Changed behaviour because of fear of crime" 0"Did not change behaviour because of fear of crime", modify
label values crime_fear crime_fear

*Fear of crime (security measures)
recode  Q43_3 2=0, gen(crime_expenses) 
label variable crime_expenses "Spent on protection measures because of fear of crime" 
label define crime_expenses 1 "Spent on protection measures" 0"Did not spend on protection measures", modify
label values crime_expenses crime_expenses

*Has considered moving to another neighbourhood due to fear of crime 
recode  Q43_5 2=0, gen(crime_moving) 
label variable crime_moving "Has considered moving neighbourhood to due to fear of crime" 

*Has considered emigrating due to fear of crime 
recode  Q43_5 2=0, gen(crime_migration) 
label variable crime_migration "Has considered emigrating due to fear of crime" 


alpha crime_fear crime_expenses crime_moving crime_migration, gen(crime_protection_index)
label variable crime_protection_index "Measures taken for crime protection" 
recode crime_protection_index 0/0.49999=0 0.5/1=1, gen(crime_protection_index_group)
label variable crime_protection_index_group  "Measures taken for crime protection (levels)" 



**************************************************************
*Reporting crime (likely)
recode Q28_3 1/3=0 4/5=1, gen(report_crime)
label variable report_crime "Likely to report a minor crime" 
recode Q28_4 1/3=0 4/5=1, gen(report_seriouscrime)
label variable report_seriouscrime "Likely to report a major crime" 


recode Q28_3 1=0 2=1 3=2 4=3 5=4, gen(report_crime_ord)
label variable report_crime_ord "Likely to report a minor crime (ordinal)" 
recode Q28_4 1=0 2=1 3=2 4=3 5=4, gen(report_seriouscrime_ord)
label variable report_seriouscrime_ord "Likely to report a major crime (ordinal)" 

*Reasons why people do not report crime 
recode  Q34_6 1/3=0 4/5=1, gen(reporting_difficult)
label variable reporting_difficult "Reporting a crime is difficult" 
recode  Q34_7 1/3=0 4/5=1, gen(reporting_useless)
label variable  reporting_useless "Reporting a crime is useless" 
recode  Q34_8 1/3=0 4/5=1, gen(reporting_retaliation)
label variable reporting_retaliation "Reporting a crime can lead to retaliation from criminals" 

*************************************************************************************************
*State violence 

*Knows someone who has suffer violence on the way to the US
recode Q47_1 2=0, gen(violence_US)
label variable violence_US "Someone who has suffered violence or abuses on their way to the US?"

*Knows someone who has been victim of police abuse 
recode Q47_2 2=0, gen(police_abuse)
label variable police_abuse "Someone who has suffered from physical or verbal abuse by state officers?"
label define police_abuse 1 "Knows of state abuse" 0"Doesn't know of state abuse", modify
label values police_abuse police_abuse

*Knows someone who has paid a bribe to security officers
recode Q47_3 2=0, gen(police_bribe)
label variable police_bribe "Someone who has paid a bribe to a police officer or a public prosecutor?"
label define police_bribe 1 "Paid bribe to police officer" 0"Did not pay bribe", modify
label values police_bribe police_bribe

*Know someone who has paid a bribe to a goverment officer
recode Q47_4 2=0, gen(officer_bribe)
label variable officer_bribe "Someone who has paid a bribe to a government officer?"

**Know someone who has paid a bribe
egen bribe = rowtotal(police_bribe-officer_bribe)
recode bribe 0=0 1/2=1
label variable bribe "Someone who has paid a bribe"

*************************************************************************************************
gen crime_state = 0 
replace crime_state = 0 if (crime_victim == 0 & police_abuse == 0)
replace crime_state = 1 if (crime_victim == 0 & police_abuse == 1)
replace crime_state = 2 if (crime_victim == 1 & police_abuse == 1)
replace crime_state = 3 if (crime_victim == 1 & police_abuse == 0)
label define crime_state 0 "Neither" 1"Abuse only" 2"Both" 3"Crime only", modify
label values crime_state crime_state
label variable crime_state "State abuse and crime victimization" 


gen crime_bribe = 0 
replace crime_bribe = 0 if (crime_victim == 0 & police_bribe == 0)
replace crime_bribe = 1 if (crime_victim == 0 & police_bribe == 1)
replace crime_bribe = 2 if (crime_victim == 1 & police_bribe == 1)
replace crime_bribe = 3 if (crime_victim == 1 & police_bribe == 0)
label define crime_bribe 0 "Neither" 1"Abuse only" 2"Both" 3"Crime only", modify
label values crime_bribe crime_bribe
label variable crime_bribe "Payment of bribes and crime victimization" 

*************************************************************************************************
*COVID
recode Q44 2=0, gen(covid_infection)
label variable covid_infection "Infected with Covid-19"
recode Q45 1=1 2/4=0, gen(covid_vaccine)
label variable covid_vaccine "Vaccinated against Covid-19"

********************************************************************
*Economic anxieties 
recode Q13_1 1/2=0 3=1 4/5=2, gen(country_economy)
recode Q13_2 1/2=0 3=1 4/5=2, gen(house_economy)
label variable country_economy  "Present economic situation in the country"
label variable house_economy "Present economic situation in the household"
label define economy 0 "Bad" 1"Neither" 2"Good", modify
label values country_economy economy
label values house_economy economy

recode house_economy 0/1=0 2=1, gen(good_house_economy)
recode country_economy 0/1=0 2=1, gen(good_country_economy)
label define good_economy 0 "Bad/Neither" 1"Good", modify
label values good_country_economy good_economy
label values good_house_economy good_economy

recode Q52 1=2 2=1 3/4=0, gen(enough_income)
label variable enough_income "Is the total household income good enough?"
label define enough_income 0 "Not enough" 1"Good enough" 2"Good enough and can save", modify
label values enough_income enough_income 
tab enough_income, gen(income_perceptions)
label variable income_perceptions1 "Income is not enough"
label variable income_perceptions2 "Income is good enough"
label variable income_perceptions3 "Income is good enough and can save"

*******************************
*2c. Migration-related Variables

**Emigration intentions
recode Q28_1 1/2=0 3/4=1, gen(emigration)
label variable emigration "Emigration_intentions"

*Migrant respondents
recode Q2 2=0, gen(migrant)  
label define migrant 0 "Nonmigrant" 1 "Migrant" 
label values migrant migrant
label variable migrant "Migrant household" 

*Return 
gen return = Q11 
label define returning 0 "Nonmigrant" 1 "Returning" 2 "Nonreturning migrant"
label values return returning 
label variable return "Returning vs nonreturning migrant household" 

*Return2 (no distinction among migrants) 
recode Q11 0=0 1=1 2=0, gen(return2)
label define returning2 0 "No return" 1 "Return"
label values return2 returning2 
label variable return2 "Returning migrant household (no distinction among migrants)" 

*Economic Remittances (non-recipients vs recipients - no distinction among migrants) 
recode Q6 0=0 2=0, gen(remittances)  
label define remittances 0 "Nonrecipient" 1 "Recipient" 
label values remittances remittances
label variable remittances "Remittance-receiving household (no distinction among migrants)" 

*Economic Remittances  
gen remittances2 = Q6   
label define remittances2 0 "Nonmigrant" 2 "Nonrecipient" 1 "Recipient" 
label values remittances2 remittances2
label variable remittances2 "Remittance-receiving households" 


save "Data ready E5.dta", replace 
